<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (arr1, arr2) {
    const map = new Map(), res = []
    for (let num of arr1) {
      map.set(num, (map.get(num) || 0) + 1)
    }
    for (let num of arr2) {
      let i = map.get(num)
      while (i-- > 0) {
        res.push(num)
      }
    }
    return res.concat(arr1.filter(num => !res.includes(num)).sort((a, b) => a - b))
  };
  console.log(arr(arr1 = [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], arr2 = [2, 1, 4, 3, 9, 6]));
</script>

</html>